home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / omniORB-2.5.0-src.tar.gz / omniORB-2.5.0-src.tar / omniORB_2.5.0 / include / omniORB2 / giopDriver.h < prev    next >
C/C++ Source or Header  |  1997-08-21  |  16KB  |  387 lines

  1. // -*- Mode: C++; -*-
  2. //                            Package   : omniORB2
  3. // giopDriver.h               Created on: 6/2/96
  4. //                            Author    : Sai Lai Lo (sll)
  5. //
  6. //    Copyright (C) 1996, 1997 Olivetti & Oracle Research Laboratory
  7. //
  8. //    This file is part of the omniORB library
  9. //
  10. //    The omniORB library is free software; you can redistribute it and/or
  11. //    modify it under the terms of the GNU Library General Public
  12. //    License as published by the Free Software Foundation; either
  13. //    version 2 of the License, or (at your option) any later version.
  14. //
  15. //    This library is distributed in the hope that it will be useful,
  16. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. //    Library General Public License for more details.
  19. //
  20. //    You should have received a copy of the GNU Library General Public
  21. //    License along with this library; if not, write to the Free
  22. //    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
  23. //    02111-1307, USA
  24. //
  25. //
  26. // Description:
  27. //    *** PROPRIETORY INTERFACE ***
  28. //
  29.  
  30. /*
  31.   $Log: giopDriver.h,v $
  32.   Revision 1.6  1997/08/21 22:20:50  sll
  33.   New system exception TRANSACTION_REQUIRED, TRANSACTION_ROLLEDBACK,
  34.   INVALID_TRANSACTION and WRONG_TRANSACION.
  35.  
  36.  * Revision 1.5  1997/05/06  16:08:20  sll
  37.  * Public release.
  38.  *
  39.   */
  40.  
  41. #ifndef __GIOPDRIVER_H__
  42. #define __GIOPDRIVER_H__
  43.  
  44. // The GIOP_C and GIOP_S classes are defined to drive the General Inter-ORB
  45. // Protocol (GIOP). The GIOP protocol is asymmetric.  GIOP_C provides the
  46. // functions to drive the client side protocol.  GIOP_S provides the server
  47. // side functions.
  48. //
  49. // GIOP_C and GIOP_S are built on top of a strand. Direct access to the strand
  50. // can be done via the NetBufferedStream class which is a public base
  51. // class of GIOP_C and GIOP_S. Typically clients of GIOP_C and GIOP_S uses
  52. // the NetBufferedStream interface to marshall and unmarshall arguments.
  53. //
  54. // Calling the constructors of GIOP_C and GIOP_S acquire a strand.
  55. // GIOP_C and GIOP_S implements the appropriate exclusive access to the
  56. // strand according to their internal states.
  57.  
  58. class _OMNIORB2_NTDLL_ GIOP_Basetypes {
  59. public:
  60.   class MessageHeader {
  61.   public:
  62.     typedef _CORBA_Char HeaderType[8];
  63.     static const HeaderType Request;
  64.     static const HeaderType Reply;
  65.     static const HeaderType CancelRequest;
  66.     static const HeaderType LocateRequest;
  67.     static const HeaderType LocateReply;
  68.     static const HeaderType CloseConnection;
  69.     static const HeaderType MessageError;
  70.   };
  71.   struct _SysExceptRepoID {
  72.     _CORBA_Char *id;
  73.     _CORBA_ULong len;
  74.  
  75.     _SysExceptRepoID(_CORBA_Char *i) {
  76.       id = i; len = strlen((const char *)i);
  77.     }
  78.   };
  79.   class SysExceptRepoID {
  80.   public:
  81.     static const _SysExceptRepoID UNKNOWN;
  82.     static const _SysExceptRepoID BAD_PARAM;
  83.     static const _SysExceptRepoID NO_MEMORY;
  84.     static const _SysExceptRepoID IMP_LIMIT;
  85.     static const _SysExceptRepoID COMM_FAILURE;
  86.     static const _SysExceptRepoID INV_OBJREF;
  87.     static const _SysExceptRepoID OBJECT_NOT_EXIST;
  88.     static const _SysExceptRepoID NO_PERMISSION;
  89.     static const _SysExceptRepoID INTERNAL;
  90.     static const _SysExceptRepoID MARSHAL;
  91.     static const _SysExceptRepoID INITIALIZE;
  92.     static const _SysExceptRepoID NO_IMPLEMENT;
  93.     static const _SysExceptRepoID BAD_TYPECODE;
  94.     static const _SysExceptRepoID BAD_OPERATION;
  95.     static const _SysExceptRepoID NO_RESOURCES;
  96.     static const _SysExceptRepoID NO_RESPONSE;
  97.     static const _SysExceptRepoID PERSIST_STORE;
  98.     static const _SysExceptRepoID BAD_INV_ORDER;
  99.     static const _SysExceptRepoID TRANSIENT;
  100.     static const _SysExceptRepoID FREE_MEM;
  101.     static const _SysExceptRepoID INV_IDENT;
  102.     static const _SysExceptRepoID INV_FLAG;
  103.     static const _SysExceptRepoID INTF_REPOS;
  104.     static const _SysExceptRepoID BAD_CONTEXT;
  105.     static const _SysExceptRepoID OBJ_ADAPTER;
  106.     static const _SysExceptRepoID DATA_CONVERSION;
  107.     static const _SysExceptRepoID TRANSACTION_REQUIRED;
  108.     static const _SysExceptRepoID TRANSACTION_ROLLEDBACK;
  109.     static const _SysExceptRepoID INVALID_TRANSACTION;
  110.     static const _SysExceptRepoID WRONG_TRANSACTION;
  111.     static const _CORBA_ULong maxIDLen;
  112.     static const _CORBA_Char *version;
  113.     static const _CORBA_ULong versionLen;
  114. #define omniORB_GIOP_Basetypes_SysExceptRepoID_maxIDLen 46
  115.   };
  116.   static size_t max_giop_message_size;
  117. };
  118.  
  119. class GIOP_C : public GIOP_Basetypes, public NetBufferedStream {
  120. public:
  121.  
  122.   GIOP_C(Rope *r);
  123.   ~GIOP_C();
  124.  
  125.   enum State { Idle,
  126.            RequestInProgress,
  127.            WaitingForReply,
  128.            ReplyIsBeingProcessed,
  129.                Zombie
  130.   };
  131.  
  132.  
  133.   // A GIOP_C instance operates in one of the following states:
  134.   //
  135.   //       Idle                  -  no request has been initiated
  136.   //       RequestInProgress     -  a request is being composed, arguments
  137.   //                                can be marshalled into the
  138.   //                                NetBufferedStream
  139.   //       WaitingForReply       -  the request has been sent, no reply
  140.   //                                has come in yet.
  141.   //       ReplyIsBeingProcessed -  a reply has started arriving, results
  142.   //                                can be unmarshalled from the
  143.   //                                NetBufferedStream
  144.   //       Zombie                -  the destructor has been called
  145.   //
  146.   // Calling the member functions InitialiseRequest(), ReceiveReply() and
  147.   // RequestCompleted() cause the GIOP_C to change state. The state transitions
  148.   // are as follows:
  149.   //                    +------------+
  150.   //                    |         |  ~GIOP_C()
  151.   //                   +----+---+         |
  152.   //                   | Zombie |<-------+
  153.   //                   +--------+
  154.   //                                    ^
  155.   //                                                   | ~GIOP_C()
  156.   //                           |
  157.   //        RequestCompleted()     +----+---+         InitialiseRequest()
  158.   //             +---------------->|  Idle  |---------------+
  159.   //             |                 +---+----+               |
  160.   //             |                     |                    V
  161.   //  +-----------------------+        |             +--------------------+
  162.   //  | ReplyIsBeingProcessed |        |             |  RequestInProgress |
  163.   //  +-----------------------+        |             +---------+----------+
  164.   //         ^                     |                       |
  165.   //             |                     |                       |
  166.   //             |                     | IssueLocateRequest()  |
  167.   //             |                 |               |
  168.   //         |                 |               |
  169.   //         |                 |               |
  170.   //         |                 |               |
  171.   //         |                     V                       |
  172.   //             |         +--------------------+           |
  173.   //             +---------|  WaitingForReply   |<-------------+
  174.   //     <got a proper     +--------------------+     ReceiveReply()
  175.   //      reply header while
  176.   //      in ReceiveReply() or IssueLocateRequest()>
  177.   //
  178.   // The constructor initialises a GIOP_C to Idle state.
  179.   //
  180.   // When the destructor is called, the state is examined. If it is *not* in
  181.   // Idle or WaitingForReply, there is something seriously wrong with the
  182.   // NetBufferedStream. Also the state of the strand, on which the
  183.   // NetBufferedStream is built, is unknown. For this reason, the strand
  184.   // is marked as dying by the destructor. The destructor may be called
  185.   // multiple times. It simply returns if the instance is already in Zombie
  186.   // state.
  187.   //
  188.   // Calling the member functions InitialiseRequest(), ReceiveReply(),
  189.   // RequestCompleted() and IssueLocateRequest() while the GIOP_C is not 
  190.   // in the appropriate state as indicated above would cause a 
  191.   // CORBA::INTERNAL() exception to be raised.
  192.   //
  193.  
  194.   void InitialiseRequest(const void          *objkey,
  195.              const size_t         objkeysize,
  196.              const char          *opname,
  197.              const size_t         opnamesize,
  198.              const size_t         msgsize,
  199.              const _CORBA_Boolean oneway);
  200.   // Initialise a Request message.
  201.   // Note: <msgsize> is the size of the whole message including the
  202.   //       GIOP message header and the Request message header.
  203.  
  204.  
  205.   GIOP::ReplyStatusType ReceiveReply();
  206.  
  207.   void RequestCompleted(_CORBA_Boolean skip=0);
  208.  
  209.   GIOP::LocateStatusType IssueLocateRequest(const void   *objkey,
  210.                         const size_t  objkeysize);
  211.  
  212.   static size_t RequestHeaderSize(const size_t objkeysize,
  213.                   const size_t opnamesize);
  214.   // Return the header size. This includes the size of the GIOP message
  215.   // header and the Request message header.
  216.  
  217.   size_t MaxMessageSize() const { return pd_max_message_size; }
  218.   // Returns the maximum size of a GIOP message (excluding the header) that
  219.   // can be delivered or received. This value is the smallest of two
  220.   // values: the ORB-wide limit and the transport dependent limit.
  221.   //
  222.   // If an incoming message exceeds this limit, the message will not be
  223.   // unmarshalled and the CORBA::COMM_FAILURE exception will be raised. The
  224.   // connection is closed as a result.
  225.   //
  226.   // If an outgoing message exceeds this limit, the CORBA::MARSHAL exception
  227.   // will be raised.
  228.  
  229. private:
  230.   State pd_state;
  231.   _CORBA_ULong pd_request_id;
  232.   _CORBA_Boolean pd_response_expected;
  233.   size_t pd_max_message_size;
  234.  
  235.   void UnMarshallSystemException();
  236.  
  237. };
  238.  
  239. class GIOP_S : public GIOP_Basetypes, public NetBufferedStream {
  240. public:
  241.  
  242.   static void dispatcher(Strand *s);
  243.   // This is the first level dispatcher. Its task is to take GIOP
  244.   // message(s) from a strand. It will handle one or more GIOP messages
  245.   // until it receives a Request message (see below), when that happens
  246.   // it will return to the caller after the request is processed.
  247.   //
  248.   // If the message is any of these:
  249.   //       LocateRequest,
  250.   //       CancelRequest,
  251.   //       MessageError,
  252.   //       CloseConnection
  253.   // it is handled by the dispatcher.
  254.   //
  255.   // If the message is Request, the dispatcher would locate the object
  256.   // implementation and perform an upcall to the stub level dispatcher of
  257.   // that object.
  258.   //
  259.  
  260.   GIOP_S(Strand *s);
  261.   ~GIOP_S();
  262.  
  263.   enum State { Idle,
  264.            RequestIsBeingProcessed,
  265.            WaitingForReply,
  266.            ReplyIsBeingComposed,
  267.            Zombie
  268.   };
  269.  
  270.   // A GIOP_S instance operates in one of the following states:
  271.   //
  272.   //      Idle                        - no request has been received
  273.   //      RequestIsBeingProcessed     - a request is being processed, arguments
  274.   //                                    can be unmarshalled from the
  275.   //                                    NetBufferedStream
  276.   //      WaitingForReply             - An upcall has been dispatched into
  277.   //                                    the object implementation
  278.   //      ReplyIsBeingComposed        - a reply is being composed, results
  279.   //                                    can be marshalled into the
  280.   //                                    NetBufferedStream
  281.   //      Zombie                      - the destructor has been called
  282.   //
  283.   // Calling the member functions RequestReceived(), InitialiseReply() and
  284.   // ReplyCompleted() cause the GIOP_S to change state. The state transitions
  285.   // are as follows:
  286.   //
  287.   //                    +------------+
  288.   //                    |         |  ~GIOP_S()
  289.   //                   +----+---+         |
  290.   //                   | Zombie |<-------+
  291.   //                   +--------+
  292.   //                                    ^
  293.   //                                                   | ~GIOP_S()
  294.   //          pd_response_expected &&   |
  295.   //          ReplyCompleted()     +----+---+         <dispatcher() got a valid
  296.   //             +---------------->|  Idle  |---------------+  request>
  297.   //             |                 +--------+               |
  298.   //             |                      ^                   V
  299.   //  +-----------------------+         |         +--------------------------+
  300.   //  | ReplyIsBeingComposed  |         |         |  RequestIsBeingProcessed |
  301.   //  +-----------------------+         |         +-----------------+--------+
  302.   //         ^                      | !pd_response_expected &&  |
  303.   //             |                      | ReplyCompleted()          |
  304.   //             |         +--------------------+                   |
  305.   //             +---------|  WaitingForReply   |<------------------+
  306.   //     InitialiseReply() +--------------------+     RequestReceived()
  307.   //
  308.   //
  309.   // The dispatcher() encapsulates the upcall to the stub level dispatcher
  310.   // with a try block that catches all system exceptions. The exception
  311.   // handlers deal with an exception according to the state of the GIOP_S
  312.   // at the time:
  313.   //
  314.   //    1. If a system exception is caught when arguments are unmarshalled or
  315.   //       results are marshalled, i.e. the GIOP_S is either in
  316.   //         RequestIsBeingProcessed or ReplyIsBeingComposed,
  317.   //       something is seriously wrong in the marshalling or unmarshalling
  318.   //       and cannot recover without destroying the strand. The destructor
  319.   //       is called with the state unchanged.
  320.   //
  321.   //    2. If a system exception is caught while the strand is in
  322.   //       WaitingForReply, the dispatcher() would completed internally the
  323.   //       reply sequence and propagate the exception back to the client.
  324.   //
  325.   // The destructor examines the state, if it is *not* in Idle, there is
  326.   // something seriously wrong with the NetBufferedStream. Also the state
  327.   // of the strand, on which the NetBufferedStream is built, is unknown.
  328.   // For this reason, the strand is marked as dying by the destructor. The
  329.   // destructor may be called multiple times. It simply returns if the instance
  330.   // is already in Zombie state.
  331.   //
  332.   // Calling the member functions RequestReceived(), InitialiseReply() and
  333.   // ReplyCompleted() while the GIOP_S is not in the appropriate state as
  334.   // indicated above would cause a CORBA::INTERNAL() exception to be raised.
  335.   //
  336.  
  337.   void RequestReceived(_CORBA_Boolean skip=0);
  338.  
  339.   void InitialiseReply(const GIOP::ReplyStatusType status,
  340.                const size_t  msgsize);
  341.   // Initialise a Reply message
  342.   // Note: <msgsize> is the size of the whole message including the
  343.   //       GIOP message header and the Request message header
  344.  
  345.   void ReplyCompleted();
  346.  
  347.   static size_t ReplyHeaderSize();
  348.   // Return the reply header size. This includes the size of the GIOP message
  349.   // header and the Reply message header
  350.  
  351.   size_t MaxMessageSize() const { return pd_max_message_size; }
  352.   // Returns the maximum size of a GIOP message (excluding the header) that
  353.   // can be delivered or received. This value is the smallest of two
  354.   // values: the ORB-wide limit and the transport dependent limit.
  355.   //
  356.   // If an incoming message exceeds this limit, a MessageError message
  357.   // will be sent and the CORBA::COMM_FAILURE exception will be raised. The
  358.   // connection is closed as a result.
  359.   //
  360.   // If an outgoing message exceeds this limit, the CORBA::MARSHAL exception
  361.   // will be raised.
  362.  
  363. private:
  364.   State pd_state;
  365.   _CORBA_ULong   pd_request_id;
  366.   _CORBA_Boolean pd_response_expected;
  367.   size_t         pd_max_message_size;
  368.  
  369. #define OMNIORB_GIOPDRIVER_GIOP_S_INLINE_BUF_SIZE 32
  370.  
  371.   _CORBA_Octet  *pd_operation;
  372.   _CORBA_Octet   pd_op_buffer[OMNIORB_GIOPDRIVER_GIOP_S_INLINE_BUF_SIZE];
  373.   _CORBA_Octet  *pd_principal;
  374.   _CORBA_Octet   pd_pr_buffer[OMNIORB_GIOPDRIVER_GIOP_S_INLINE_BUF_SIZE];
  375.  
  376.   omniObjectKey pd_objkey;
  377.  
  378.   void HandleRequest(_CORBA_Boolean byteorder);
  379.   void HandleLocateRequest(_CORBA_Boolean byteorder);
  380.   void HandleCancelRequest(_CORBA_Boolean byteorder);
  381.   void HandleMessageError();
  382.   void HandleCloseConnection();
  383.   void SendMsgErrorMessage();
  384. };
  385.  
  386. #endif // __GIOPDRIVER_H__
  387.